package ru.spb.osll.myfit.fixtures;

import ru.spb.osll.myfit.client.service.PageExecutingService;
import ru.spb.osll.myfit.common.GlobalContainer;
import ru.spb.osll.myfit.common.Page;
import ru.spb.osll.myfit.common.PageExecutingResult;
import ru.spb.osll.myfit.common.PageExecutingResult.PageExecutingState;
import ru.spb.osll.myfit.fixtures.base.OneLineFixture;

public class ExecuteTestFixture extends OneLineFixture {
	public boolean executeTest() {
		PageExecutingService pageExecutingService = GlobalContainer.instance().getPageExecutingService();
		PageExecutingResult res = pageExecutingService.executePage("");
		while (res.getState() == PageExecutingState.PROGRESS) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			res = pageExecutingService.executePage("");
		}
		Page testResult = new Page();

		testResult.getElements().addAll(res.getExecutedTables());

		GlobalContainer.instance().setTestResult(testResult);
		return true;
	}

	public static String[] getTestTableTemplates() {
		return new String[] { "|execute test|\n" };
	}
}
